var app = getApp();//引用app.js
var commonURL = app.data.baseURL;
var commonURLYY = app.data.newURL;
var commonURLXX = app.data.lastURL;
var page = 1;//页码
var GZHid = 53;//公众号id
var dataLists = {};//缓存商品列表数据
//var commonURL=appjs.data.baseURL;
Page({
  data: {
    cid: "",//分类id
    ctxt: "",//分类名称，用于点击时更换标题
    imgUrls: [],
    hasblock: false,
    navbar: [],
    userpasswd: {},
    hehuoren: false,
    xiaoqudw: '',
    currentdate: '',
    cart_num: 0,
    msmpage: 1,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    navbarTop: [],
    countDownDay: '00',
    countDownHour: '00',
    countDownMinute: '00',
    countDownSecond: '00',
    lists: [],
    totalPrice: 0,   //合计价格
    count: 0,        //合计总数
    showDialog: false,
    showDetail: false,
    selectProduct: {},  //选择的商品
    opstions: [],      //规格项
    guige: {
      price: "0.00",
      list: [
        {
          id: "",
          name: ""
        }
      ]
    },
    guigeOptions: [],
    currentItem: [],
    num_count: 1
  }, globalData: {
    userInfo: null
  },
  getList: function () {
    var that = this;
    try {
      wx.getStorage({
        key: 'xiaoqu',
        success: function (res) {
          var xqname = res.data.item.name
          wx.request({
            url: commonURLXX + 'op=uniacid_shop',
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              console.log(res)
              var sname = res.data.set.sname
              var title = xqname + '-' + sname
              wx.setNavigationBarTitle({ title: title });//设置title文字
            }
          })
          wx.request({//商品购买列表
            url: commonURLYY + 'op=getbuylist',
            data: { page: 1, uniacid: app.data.GZHid, areaid: res.data.item.id },
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              var data = res.data.list;
              that.setData({
                pylists: data
              })
              var nickname = '';
              for (var i = 0; i < data.length; i++) {
                if (data[i].nickname.length > 10) {
                  nickname = "pylist[" + i + "].nickname"
                  that.setData({
                    [nickname]: data[i].nickname.substring(0, 10) + '...'
                  })
                }
              }
            },
            fail: function (res) {
              wx.showToast({
                title: '获取列表失败',
              })
            }
          })
        }
      })
    } catch (err) {
      wx.showToast({
        title: err.message,
      })
    }
  },
  onLoad: function (options) {
    if (options.xiaoqu) {//判断是否听过分享链接进入的
      wx.setStorage({
        key: 'xiaoqu',
        data: JSON.parse(options.xiaoqu),
        success: function (res) {
          console.log('设置成功')
        },
        fail: function (res) {
          console.log('设置失败')
        }
      })
    }
    var that = this;
    var xqname = ''
    var sname = ''
    var title = ''
    wx.getStorage({
      key: 'xiaoqu',
      success: function (res) {
        var openId = app.data.openid || wx.getStorageSync('openid');
        that.setData({
          areaIds: res.data.item.id
        })
        wx.request({
          url: commonURLYY + 'op=cart_view',
          data: {
            openid: openId,
            areaid: res.data.item.id
          },
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            that.setData({
              allLists: res.data.list
            })
          }
        })
      }
    })
    this.getList();
    wx.request({
      url: app.data.baseURL + 'op=getWXACodeUnlimit',
      data: {
        appid: app.data.appid,
        secret: app.data.secret,
        uniacid: app.data.GZHid,
        opneid: app.data.openid
      },
      success: function (res) {
        wx.downloadFile({
          url: res.data.data.surl,
          type: 'image',
          success: function (res) {
            wx.setStorageSync('shareqrImg', res.tempFilePath)
          }, fail: function (res) {
          }, complete: function (res) {
          }
        })
      }
    })
    // //调用应用实例的方法获取全局数据
    //that.ajaxLists(page,that.data.cid);
    // wx.request({
    //     url: commonURLYY + 'op=fenlei',
    //     data: {
    //         page: page
    //     },
    //     header: {
    //         'content-type': 'application/json'
    //     },
    //     success: function (res) {
    //       console.log(res.data.menuList,888888888)
    //         that.setData({
    //             navbarTop: res.data.menuList
    //         })
    //         // this.data.navbarTop = res.data.menuList;
    //         //   console.log(res.data.menuList)
    //     }
    // })

    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success: function (res) {
              console.log(res.userInfo, '用户信息')
              //用户已经授权过
            }
          })
        } else {
          that.setData({
            Userinfo: true
          })
        }
        // console.log(res.authSetting['scope.userInfo'],1236664)
      }
    })
    wx.getUserInfo({
      success: function (res) {
        console.log(res, 1987666)
        that.globalData.userInfo = res.userInfo;
        typeof cb == "function" && cb(that.globalData.userInfo);
        wx.request({
          url: app.data.baseURL + 'op=check_member',
          data: {
            appid: app.data.appid,
            encryptedData: res.encryptedData,
            iv: res.iv,
            session_key: app.data.session_key,
            openid: wx.getStorageSync('openid'),
            nickname: res.userInfo.nickName,
            avatar: res.userInfo.avatarUrl,
            gender: res.userInfo.gender,
            province: res.userInfo.province,
            city: res.userInfo.city,
            gender: res.userInfo.gender,
            mid: app.data.mid ? app.data.mid : '',
            xcx: 1
          },
          success: function (res) {
            // console.log(res.data);
            var data = res.data.member;
            if (data.addmobile && data.addname) {
              wx.setStorage({
                key: "add",
                data: {
                  addmobile: data.addmobile,
                  addname: data.addname
                }
              })
            }
          }
        })
      }
    })
    var openId = app.data.openid || wx.getStorageSync('openid')
    wx.request({
      url: commonURLYY + 'op=cart_view',
      data: {
        openid: openId
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        var lists = res.data.list;
        var num = 0;
        for (var i = 0; i < lists.length; i++) {
          num = num + lists[i].num;
        }
        console.log(num, ':num')
        wx.setTabBarBadge({
          index: 1,
          text: '' + num
        })
        that.setData({
          cart_num: num
        })
      }
    })

      that.getNowFormatDate();
    wx.getStorage({//获取小区地址
      key: 'xiaoqu',
      success: function (res) {
        console.log(res.data.item, "xiaoqu")
        that.setData({
          region: res.data.item,
          xiaoqudw: res.data.item.name,
          phone: res.data.item.join_hotline,
          phone1: res.data.item.merchant_entry,
          servicePhone: res.data.item.service_hotline
        });
        // wx.request({//获取是否团长
        //   url: commonURL + 'op=is_area_commander',
        //   data: { "areaid": res.data.item.id, "openid": wx.getStorageSync('openid'), "uniacid": app.data.GZHid },
        //   header: {
        //     'content-type': 'application/json'
        //   },
        //   success: function (res) {
        //     if (res.data.status == 1) {
        //       var navbarTop = [
        //         // { name: '商城小区', id: 2, url: '../recommend/recommend' },
        //         { name: '合伙人商城', id: 3, url: '../mall_village/mall_village' },
        //         // { name: '预约活动', id: 4, url: '../jielong_list/jielong_list' },
        //         { name: '爆品接龙', id: 5, url: '../jielong_list/jielong_list' }
        //       ]
        //       that.setData({
        //         navbarTop: navbarTop
        //       })
        //     } else {
        //       var navbarTop = [
        //         // { name: '商城小区', id: 2, url: '../recommend/recommend' }
        //         // { name: '预约活动', id: 3, url: '../jielong_list/jielong_list' },
        //         { name: '爆品接龙', id: 4, url: '../jielong_list/jielong_list' }
        //       ]
        //       that.setData({
        //         navbarTop: navbarTop
        //       })
        //     }
        //   }
        // })
      }
    })
    wx.request({
      url: commonURLXX + 'op=uniacid_shop',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.setNavigationBarTitle({ title: res.data.sname });//设置title文字
      }
    })
  },
  setTimesklp: function (time,index) {
    var that = this;
    var num_timearr = [];
      var timer = setInterval(function () {
        var obj = {};
        time = Number(time)
        var totalSecond = time - Date.parse(new Date()) / 1000; //这边传一个时间戳
        if (totalSecond>=0){
          // 秒数
          var second = totalSecond;
          // 天数位
          var day = Math.floor(second / 3600 / 24);
          var dayStr = day.toString();
          if (dayStr.length == 1) dayStr = '0' + dayStr;
          // 小时位
          var hr = Math.floor((second - day * 3600 * 24) / 3600);
          var hrStr = hr.toString();
          if (hrStr.length == 1) hrStr = '0' + hrStr;
          // 分钟位
          var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
          var minStr = min.toString();
          if (minStr.length == 1) minStr = '0' + minStr;
          // 秒位
          var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
          var secStr = sec.toString();
          if (secStr.length == 1) secStr = '0' + secStr;
          var num_time = {};
          num_time = { dayStr: dayStr, hrStr: hrStr, minStr: minStr, secStr: secStr }
          var count_down = "lists[" + index + "].count_down";
          that.setData({
            [count_down]: num_time
          })
        }else{
          num_time = { dayStr: '00', hrStr: '00', minStr: '00', secStr: '00' }
          var count_down = "lists[" + index + "].count_down";
          that.setData({
            [count_down]: num_time
          })
        }
      }, 1000)
  },
  bindGetUserInfo: function (e) {
    var that = this
    if (e.detail.userInfo) {
      that.setData({
        Userinfo: false
      })
      wx.getUserInfo({
        success: function (res) {
          console.log(res, '用户信息')
          that.globalData.userInfo = res.userInfo;
          typeof cb == "function" && cb(that.globalData.userInfo);
          wx.request({
            url: app.data.baseURL + 'op=check_member',
            data: {
              appid: app.data.appid,
              encryptedData: res.encryptedData,
              iv: res.iv,
              session_key: app.data.session_key,
              openid: wx.getStorageSync('openid'),
              nickname: res.userInfo.nickName,
              avatar: res.userInfo.avatarUrl,
              gender: res.userInfo.gender,
              province: res.userInfo.province,
              city: res.userInfo.city,
              gender: res.userInfo.gender,
              mid: app.data.mid ? app.data.mid : '',
              xcx: 1
            },
            success: function (res) {
              var data = res.data.member;
              if (data.addmobile && data.addname) {
                wx.setStorage({
                  key: "add",
                  data: {
                    addmobile: data.addmobile,
                    addname: data.addname
                  }
                })
              }
            }
          })
        }
      })
    } else {
      that.setData({
        Userinfo: true
      })
    }
  },
  calling: function () {
    var that = this
    wx.makePhoneCall({
      phoneNumber: that.data.phone,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },
  calling1: function () {
    var that = this
    wx.makePhoneCall({
      phoneNumber: that.data.phone1,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },
  get_splist: function () {
    var that = this
    var num = that.data.msmpage;
    num++;
    wx.request({//商品购买列表
      url: commonURLYY + 'op=getbuylist',
      data: { page: num, uniacid: app.data.GZHid, areaid: that.data.region.id },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        if (res.data.list.length > 0) {
          console.log(res.data.list, 888888)
          that.setData({
            msmpage: num
          })
          var data = res.data.list
          that.setData({
            pylist: that.data.pylist.concat(data)
          })
          var nickname = '';
          for (var i = 0; i < data.length; i++) {
            if (data[i].nickname.length > 10) {
              nickname = "pylist[" + i + "].nickname"
              that.setData({
                [nickname]: data[i].nickname.substring(0, 10) + '...'
              })
            }
          }
        } else {
          num--;
          wx.showToast({
            title: '已是全部记录',
            icon: 'success',
            duration: 1000
          })
        }
      }
    })
  },
  getNowFormatDate: function () {//自提时间显示
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    this.setData({
      currentdate: currentdate
    })
  },
  formatDateTime: function (timeStamp) {
    var date = new Date(); date.setTime(timeStamp * 1000); var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); h = h < 10 ? ('0' + h) : h; var minute = date.getMinutes(); var second = date.getSeconds(); minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second; return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  },
  navTo: function () {
    wx.navigateTo({
      url: '../myorder/myorder'
    })
  },
  // handler: function (e) {
  //   if (e.detail.authSetting["scope.userLocation"]) {//如果打开了地理位置，就会为true
  //     this.setData({
  //       showFlag: true
  //     })
  //     var that = this;
  //     wx.getStorage({//获取小区地址
  //       key: 'xiaoqu',
  //       success: function (res) {
  //             console.log(res.data.item, "xiaoqu")
  //             that.setData({
  //               region: res.data.item,
  //               xiaoqudw: res.data.item.name,
  //               phone: res.data.item.join_hotline,
  //               phone1: res.data.item.merchant_entry,
  //             });
  //           }
  //         })
  //       }
  //   }
  // },
  //  modalcnt: function () {
  //       var that=this
  //       wx.showModal({
  //         title: '提示',
  //         content: '是否退出合伙人登录',
  //         success: function (res) {
  //           if (res.confirm) {
  //             console.log('用户点击确定')
  //             wx.removeStorage({
  //               key: 'userpasswd',
  //               success: function (res) {
  //                 console.log(res.data)
  //                 that.setData({
  //                   userpasswd:{},
  //                   hehuoren: false
  //                 })
  //               }
  //             })
  //           } else if (res.cancel) {
  //             console.log('用户点击取消')
  //           }
  //         }
  //       })
  //     },
  // 上拉加载回调接口
  timestampToTime:function (timestamp) {
    var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D =  (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate() ) + '-';
    var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
    var m =  (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
    return Y + M + D + h + m + s;
  },
  onReachBottom: function () {
    var that = this;
    // 我们用total和count来控制分页，total代表已请求数据的总数，count代表每次请求的个数。
    // 上拉时需把total在原来的基础上加上count，代表从count条后的数据开始请求。
    page++;
    if (that.xiaoqudw != '') {
      wx.getStorage({//获取小区地址
        key: 'xiaoqu',
        success: function (res) {
          console.log(res.data.item, "xiaoqu")
          that.setData({
            region: res.data.item,
            xiaoqudw: res.data.item.name,
            phone: res.data.item.join_hotline,
            phone1: res.data.item.merchant_entry,
          });
          wx.request({//加载商品列表
            url: commonURLYY + 'op=ajax',
            data: {
              page: page,
              pagesize: 1,
              cid: that.data.cid,
              areaid: res.data.item.id,
              openid: app.data.openid
            },
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              console.log(res)
              that.setData({
                allGoodsList: that.data.allGoodsList.concat(res.data.list)
              })
              if (res.data.list.length < 1) {
                wx.showToast({
                  title: '全部商品加载完成',
                  icon: 'success',
                  duration: 1000
                })
                return false;
              }
              wx.showToast({
                title: '商品加载中...',
                icon: 'loading',
                duration: 700
              })
              var num_timearr = [];
              console.log(res.data.list, 666)
              var timenum = 1
              for (var i = 0, lists = []; i < res.data.list.length; i++) {
                // var obj = {};
                // var indexid = obj["id"] = res.data.list[i].id;
                // if (res.data.list[i].hasoption == 1) {
                //   for (var j = 0; j < res.data.list[i].options.length; j++) {
                //     console.log(res.data.list[i].options[j].cnum)
                //     aCnum += Number(res.data.list[i].options[j].cnum)
                //   }
                //   obj["aCnum"] = aCnum;
                // }
                // var indexid = obj["id"] = res.data.list[i].id;
                // that.setTimesklp(res.data.list[i].spike_start, i);
                // timenum = Number(res.data.list[i].spike_end)
                // that.setTimesklp(res.data.list[i].spike_start, i);
                var obj = {};
                var aCnum = 0;
                if (res.data.list[i].hasoption == 1) {
                  for (var j = 0; j < res.data.list[i].options.length; j++) {
                    console.log(res.data.list[i].options[j].cnum)
                    aCnum += Number(res.data.list[i].options[j].cnum)
                  }
                  obj["aCnum"] = aCnum;
                }
                var indexid = obj["id"] = res.data.list[i].id;
                that.setTimesklp(res.data.list[i].spike_start, i+that.data.lists.length);
                obj["spike_end"] = that.timestampToTime(Number(res.data.list[i].spike_end));
                obj["spike_start"] = that.timestampToTime(Number(res.data.list[i].spike_start));
                obj["spikeT"] = res.data.list[i].spikeT;
                obj["spike_over"] = res.data.list[i].spike_end;
                obj["spike_on"] = res.data.list[i].spike_start;
                obj["cnum"] = res.data.list[i].cnum;
                obj["spike"] = res.data.list[i].spike;
                obj["self_time_start"] = that.timestampToTime(Number(res.data.list[i].self_time_start));
                obj["self_time_end"] = that.timestampToTime(Number(res.data.list[i].self_time_end));
                obj["is_self_time"] = res.data.list[i].is_self_time;
                obj["gnum"] = res.data.list[i].gnum;
                obj["count_down"] = that.data.num_time;
                obj["img"] = res.data.list[i].gimg;
                obj["title"] = res.data.list[i].gname;
                obj["price"] = res.data.list[i].oprice;//单买价
                obj["gprice"] = res.data.list[i].gprice;//团购价
                obj["peoplenum"] = res.data.list[i].groupnum;
                obj["unit"] = res.data.list[i].unit;
                obj["mprice"] = res.data.list[i].mprice;//市场价
                obj["salenum"] = res.data.list[i].salenum;
                obj["xiangqing"] = res.data.list[i].gdesc;
                obj["shuxing"] = res.data.list[i].params;
                obj["advs"] = res.data.list[i].advs;
                obj["options"] = res.data.list[i].options;
                obj["kucun"] = res.data.list[i].gnum;
                obj["selltype"] = res.data.list[i].selltype;
                obj["hasoption"] = res.data.list[i].hasoption;//是否有规格 0没有 ，1有
                obj["weight"] = res.data.list[i].weight;//重量，用于计算运费
                obj["deliverytype"] = res.data.list[i].deliverytype;//配送方式
                obj["jielong"] = res.data.list[i].jielong;//接龙
                if (res.data.list[i].isshow == '3' || res.data.list[i].gnum == "0") {
                  obj["smtuan"] = "售罄";
                  obj["backg"] = "#aaa";
                  obj["url"] = '';
                } else {
                  if (res.data.list[i].selltype == '0') {
                    obj["url"] = '../index_only_detail/index_only_detail?id=' + indexid;
                    if (res.data.list[i].spike == 1) {
                      if (res.data.list[i].spike_end <= Date.parse(new Date()) / 1000) {
                        obj["url"] = '';
                        obj["backg"] = "#aaa";
                        obj["smtuan"] = '活动结束'
                      }
                    }
                  } else {
                    if (res.data.list[i].jielong == '0') {
                      obj["smtuan"] = that.select_tuan(res.data.list[i].selltype);
                      obj["url"] = '../index_detail/index_detail?id=' + indexid;
                    } else {
                      obj["smtuan"] = that.select_tuan(res.data.list[i].selltype);
                      obj["url"] = '../detail_jielong/detail_jielong?id=' + indexid;
                    }
                    if (res.data.list[i].spikeT == 1) {
                      if (res.data.list[i].spike_end <= Date.parse(new Date()) / 1000) {
                        obj["url"] = '';
                        obj["backg"] = "#aaa";
                        obj["smtuan"] = '活动结束'
                      }
                    }
                  }
                }
                lists.push(obj);
                dataLists[indexid] = obj;
              }
              that.setData({
                lists: that.data.lists.concat(lists)
              });
              wx.getStorage({
                key: 'indexLists',
                success: function (res) {
                  var data = res.data[indexid];
                  if (!res.data[indexid]) {//如果缓存中不存在对应的商品，就ajax加载数据
                    wx.setStorage({
                      key: "indexLists",
                      data: dataLists
                    })
                  }
                }
              })
            }
          })
        },
        fail: function () {
          wx.navigateTo({
            url: '../cell_selection/cell_selection',
          })
        }
      })
    }
  },
  upper: function () {
    this.ajaxLists(1, "");
    wx.setNavigationBarTitle({ title: xqname })
  },
  // leixingQH: function (e) {//点击类型加载不同数据
  //   var that = this;
  //   page = 1;
  //   console.log(e);
  //   var id = e.currentTarget.dataset.id;
  //   var Bartitle = e.currentTarget.dataset.title;
  //   if (id === that.data.cid) return false;
  //   that.setData({ cid: id })
  //   console.log(id);
  //   wx.request({//根据分类加载商品列表
  //     url: commonURLYY + 'op=ajax',
  //     data: {
  //       page: page,
  //       pagesize: 10,
  //       cid: id,
  //       // areaid: areaid,
  //       "type": 1
  //     },
  //     header: {
  //       'content-type': 'application/json'
  //     },
  //     success: function (res) {
  //       console.log(res)
  //       wx.setNavigationBarTitle({ title: Bartitle });//设置title文字
  //       for (var i = 0, lists = []; i < res.data.list.length; i++) {
  //         var obj = {};
  //         var indexid = obj["id"] = res.data.list[i].id;
  //         obj["img"] = res.data.list[i].gimg;
  //         obj["cnum"] = res.data.list[i].cnum;
  //         obj["title"] = res.data.list[i].gname;
  //         obj["price"] = res.data.list[i].oprice;//单买价
  //         obj["gprice"] = res.data.list[i].gprice;//团购价
  //         obj["peoplenum"] = res.data.list[i].groupnum;
  //         obj["is_self_time"] = res.data.list[i].is_self_time
  //         obj["self_time_start"] = that.fmtDate(Number(res.data.list[i].self_time_start))
  //         obj["self_time_end"] = that.fmtDate(Number(res.data.list[i].self_time_end))
  //         obj["unit"] = res.data.list[i].unit;
  //         obj["mprice"] = res.data.list[i].mprice;//市场价
  //         obj["salenum"] = res.data.list[i].salenum;
  //         obj["xiangqing"] = res.data.list[i].gdesc;
  //         obj["shuxing"] = res.data.list[i].params;
  //         obj["advs"] = res.data.list[i].advs;
  //         obj["kucun"] = res.data.list[i].gnum;
  //         obj["selltype"] = res.data.list[i].selltype;
  //         obj["hasoption"] = res.data.list[i].hasoption;//是否有规格 0没有 ，1有
  //         obj["weight"] = res.data.list[i].weight;//重量，用于计算运费
  //         obj["deliverytype"] = res.data.list[i].deliverytype;//配送方式
  //         obj["jielong"] = res.data.list[i].jielong;//接龙
  //         obj["jielong"] = res.data.list[i].jielong;
  //         if (res.data.list[i].isshow == '3' || res.data.list[i].gnum == "0") {
  //           obj["smtuan"] = "售罄";
  //           obj["backg"] = "#aaa";
  //           obj["url"] = '';
  //         } else {
  //           if (res.data.list[i].selltype == '0') {
  //             obj["url"] = '../index_only_detail/index_only_detail?id=' + indexid;
  //           } else {
  //             if (res.data.list[i].jielong == '0') {
  //               obj["smtuan"] = that.select_tuan(res.data.list[i].selltype);
  //               obj["url"] = '../index_detail/index_detail?id=' + indexid;
  //             } else {
  //               obj["smtuan"] = that.select_tuan(res.data.list[i].selltype);
  //               obj["url"] = '../detail_jielong/detail_jielong?id=' + indexid;
  //             }
  //           }
  //         }
  //         lists.push(obj);
  //         dataLists[indexid] = obj;
  //         wx.getStorage({
  //           key: 'indexLists',
  //           success: function (res) {
  //             var data = res.data[indexid];
  //             //console.log(res.data);
  //             if (!res.data[indexid]) {//如果缓存中不存在对应的商品，就ajax加载数据
  //               wx.setStorage({
  //                 key: "indexLists",
  //                 data: dataLists
  //               })
  //             }
  //           }
  //         })
  //       }
  //       that.setData({
  //         lists: lists
  //       })

  //     }
  //   })
  // },
  fmtDate: function (timeStamp) {
    var date = new Date(); date.setTime(timeStamp * 1000); var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); h = h < 10 ? ('0' + h) : h; var minute = date.getMinutes(); var second = date.getSeconds(); minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second; return y + '-' + m + '-' + d;
  },
  createNonceStr: function () {
    var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = chars.length;
    var pwd = '';
    for (var i = 0; i < 32; i++) {
      pwd += chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd
  },
  onShow: function () {//页面显示加载数据
    page = 1;
    var that = this;
    var openId = app.data.openid || wx.getStorageSync('openid');
    var nonce_str = that.createNonceStr();
    wx.request({
      url: commonURL + 'op=check_order',
      data: {
        openid: wx.getStorageSync('openid'),
        uniacid: app.data.GZHid,
        nonce_str: nonce_str,
        mch_id: app.data.mch_id,
        paykey: app.data.paykey,
        appid: app.data.appid
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res, 'lalala')
      }
    })
    wx.getStorage({//获取小区地址
      key: 'xiaoqu',
      success: function (res) {
        console.log(res.data.item, "xiaoqu")
        that.setData({
          region: res.data.item,
          xiaoqudw: res.data.item.name,
          phone: res.data.item.join_hotline,
          phone1: res.data.item.merchant_entry,
          TZid: res.data.item.id
        });
        wx.request({//获取是否团长
          url: commonURL + 'op=is_area_commander',
          data: { "areaid": res.data.item.id, "openid": wx.getStorageSync('openid'), "uniacid": app.data.GZHid },
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            if (res.data.status == 1) {
              var navbarTop = [
                // { name: '商城小区', id: 2, url: '../recommend/recommend' },
                { name: '合伙人商城', id: 3, url: '../mall_village/mall_village' },
                // { name: '预约活动', id: 4, url: '../jielong_list/jielong_list' },
                { name: '爆品接龙', id: 5, url: '../jielong_list/jielong_list' }
              ]
              that.setData({
                navbarTop: navbarTop
              })
            } else {
              var navbarTop = [
                // { name: '商城小区', id: 2, url: '../recommend/recommend' }
                // { name: '预约活动', id: 3, url: '../jielong_list/jielong_list' },
                { name: '爆品接龙', id: 4, url: '../jielong_list/jielong_list' }
              ]
              that.setData({
                navbarTop: navbarTop
              })
            }
          }

        })
        wx.getStorage({//获取小区地址
          key: 'xiaoqu',
          success: function (res) {
            wx.request({//商品购买列表
              url: commonURLYY + 'op=getbuylist',
              data: { page: 1, uniacid: app.data.GZHid, areaid: res.data.item.id },
              header: {
                'content-type': 'application/json'
              },
              success: function (res) {
                var data = res.data.list;

                that.setData({
                  pylist: data
                })
                var nickname = '';
                for(var i=0;i<data.length;i++){
                  if(data[i].nickname.length>10){
                    nickname="pylist["+i+"].nickname"
                    that.setData({
                      [nickname]: data[i].nickname.substring(0,10)+'...'
                    })
                  }
                }
              }
            })
          }
        })
      },
      fail: function () {
        wx.navigateTo({
          url: '../cell_selection/cell_selection',
        })
      }
    })
    wx.getUserInfo({
      success: function (res) {
        console.log(res, '用户信息')
        that.globalData.userInfo = res.userInfo;
        typeof cb == "function" && cb(that.globalData.userInfo);
        wx.request({
          url: app.data.baseURL + 'op=check_member',
          data: {
            appid: app.data.appid,
            encryptedData: res.encryptedData,
            iv: res.iv,
            session_key: app.data.session_key,
            openid: wx.getStorageSync('openid'),
            nickname: res.userInfo.nickName,
            avatar: res.userInfo.avatarUrl,
            gender: res.userInfo.gender,
            province: res.userInfo.province,
            city: res.userInfo.city,
            gender: res.userInfo.gender,
            mid: app.data.mid ? app.data.mid : '',
            xcx: 1
          },
          success: function (res) {
            // console.log(res.data);
            var data = res.data.member;
            if (data.addmobile && data.addname) {
              wx.setStorage({
                key: "add",
                data: {
                  addmobile: data.addmobile,
                  addname: data.addname
                }
              })
            }
          }
        })
      }
    })
    var xqname = ''
    var sname = ''
    var title = ''
    wx.getStorage({
      key: 'xiaoqu',
      success: function (res) {
        xqname = res.data.item.name
        wx.request({
          url: commonURLXX + 'op=uniacid_shop',
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            sname = res.data.set.sname
            title = xqname + '-' + sname
            wx.setNavigationBarTitle({ title: title });//设置title文字
          }
        })
      }
    })
    wx.request({
      url: commonURLYY + 'op=cart_view&ii=',
      data: {
        openid: openId
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        var lists = res.data.list;
        var num = 0;
        for (var i = 0; i < lists.length; i++) {
          num = num + lists[i].num;
        }
        wx.setTabBarBadge({
          index: 1,
          text: '' + num
        })
        that.setData({
          cart_num: num
        })
      }
    })
    // }

    wx.request({//banner
      url: commonURL + 'op=banner',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        for (var i = 0, banner = []; i < res.data.length; i++) {
          banner.push(res.data[i].thumb);
        }
        that.setData({
          "imgUrls": banner,
        });
      }
    })
    wx.getStorage({
      key: 'userpasswd',
      success: function (res) {
        if (res.data) {
          that.setData({
            userpasswd: res.data,
            hehuoren: true
          })
        }
      }
    })
    wx.request({//商品分类
      url: commonURL + 'op=category',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        for (var i = 0, navbar = []; i < res.data.length; i++) {
          var obj = {};
          obj["img"] = res.data[i].smallthumb;
          obj["txt"] = res.data[i].name;
          obj["id"] = res.data[i].id;
          navbar.push(obj);
        }
        that.setData({
          "navbar": navbar,
        });
      }
    })
    this.ajaxLists(page, this.data.cid);
  },
  onShareAppMessage: function () {
    var xiaoqu = JSON.stringify(wx.getStorageSync('xiaoqu'));
    return {
      title: this.data.ctxt,
      path: '/pages/index/index?xiaoqu=' + xiaoqu,
      success: function (res) {
        console.log(res);
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        console.log(res)
      }
    }
  },
  onPullDownRefresh: function () {//页面下拉加载首页数据
    this.ajaxLists(1, "");
    wx.setNavigationBarTitle({ title: '首页' })
  },
  ajaxLists: function (num, cid) {
    var that = this;
    page = num;
    var areaid = '';
    if (that.xiaoqudw != '') {
      wx.getStorage({//获取小区地址
        key: 'xiaoqu',
        success: function (res) {
          console.log(res.data.item, "xiaoqu")
          that.setData({
            region: res.data.item,
            xiaoqudw: res.data.item.name,
            phone: res.data.item.join_hotline,
            phone1: res.data.item.merchant_entry,
            // phone: res.data.item.
          });
         if(wx.getStorageSync('xiaoqu').id){
           var id = wx.getStorageSync('xiaoqu').id;
           console.log(wx.getStorageSync('xiaoqu').id)
           wx.request({
             url: commonURL + 'op=checkarea',
             data: { areaid: id,uniacid: app.data.GZHid},
             header: {
               'content-type': 'application/json'
             },
             success: function (res) {
               console.log(res)
               if(res.data.status==0){
                 wx.showModal({
                   title: '提示',
                   showCancel:false,
                   content: '该小区或团长已失效，请重新选择',
                   complete: function (res) {
                     wx.navigateTo({
                       url: '../cell_selection/cell_selection',
                     })
                   }
                 })
               }
             }
           })
         }
          areaid = res.data.item.id
          wx.request({//加载商品列表
            url: commonURLYY + 'op=ajax',
            data: {
              page: num,
              pagesize: 1,
              cid: cid,
              areaid: areaid
            },
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              console.log(res)
              that.setData({
                allGoodsList:res.data.list
              })
              var num_timearr = [];
              var timenum = 1;

              for (var i = 0, lists = []; i < res.data.list.length; i++) {
                var obj = {};
                var aCnum = 0;
                if (res.data.list[i].hasoption==1){
                  for (var j = 0; j < res.data.list[i].options.length; j++) {
                    console.log(res.data.list[i].options[j].cnum)
                    aCnum +=Number(res.data.list[i].options[j].cnum)
                  }
                  obj["aCnum"] = aCnum;
                }
                var indexid = obj["id"] = res.data.list[i].id;
                that.setTimesklp(res.data.list[i].spike_start,i);
                obj["spike_end"] = that.timestampToTime(Number(res.data.list[i].spike_end));
                obj["spike_start"] = that.timestampToTime(Number(res.data.list[i].spike_start));
                obj["spikeT"] = res.data.list[i].spikeT;
                obj["cnum"] = res.data.list[i].cnum;
                obj["spike"] = res.data.list[i].spike;
                obj["spike_over"] = res.data.list[i].spike_end;
                obj["self_time_start"] = that.timestampToTime(Number(res.data.list[i].self_time_start));
                obj["self_time_end"] = that.timestampToTime(Number(res.data.list[i].self_time_end));
                obj["is_self_time"] = res.data.list[i].is_self_time;
                obj["spike_on"] = res.data.list[i].spike_start;
                obj["gnum"] = res.data.list[i].gnum;
                obj["count_down"] = that.data.num_time;
                obj["img"] = res.data.list[i].gimg;
                obj["title"] = res.data.list[i].gname;
                obj["price"] = res.data.list[i].oprice;//单买价
                obj["gprice"] = res.data.list[i].gprice;//团购价
                obj["peoplenum"] = res.data.list[i].groupnum;
                obj["unit"] = res.data.list[i].unit;
                obj["mprice"] = res.data.list[i].mprice;//市场价
                obj["salenum"] = res.data.list[i].salenum;
                obj["xiangqing"] = res.data.list[i].gdesc;
                obj["shuxing"] = res.data.list[i].params;
                obj["advs"] = res.data.list[i].advs;
                obj["options"] = res.data.list[i].options;
                obj["kucun"] = res.data.list[i].gnum;
                obj["selltype"] = res.data.list[i].selltype;
                obj["hasoption"] = res.data.list[i].hasoption;//是否有规格 0没有 ，1有
                obj["weight"] = res.data.list[i].weight;//重量，用于计算运费
                obj["deliverytype"] = res.data.list[i].deliverytype;//配送方式
                obj["jielong"] = res.data.list[i].jielong;//接龙
                if (res.data.list[i].isshow == '3' || res.data.list[i].gnum == "0") {
                  obj["smtuan"] = "售罄";
                  obj["backg"] = "#aaa";
                  obj["url"] = '';
                } else {
                  if (res.data.list[i].selltype == '0') {
                    obj["url"] = '../index_only_detail/index_only_detail?id=' + indexid;
                    if (res.data.list[i].spike == 1) {
                      if (res.data.list[i].spike_end <= Date.parse(new Date()) / 1000) {
                        obj["url"] = '';
                        obj["backg"] = "#aaa";
                        obj["smtuan"] = '活动结束'
                      }
                    }
                  } else {
                    if (res.data.list[i].jielong == '0') {
                      obj["smtuan"] = that.select_tuan(res.data.list[i].selltype);
                      obj["url"] = '../index_detail/index_detail?id=' + indexid;
                    } else {
                      obj["smtuan"] = that.select_tuan(res.data.list[i].selltype);
                      obj["url"] = '../detail_jielong/detail_jielong?id=' + indexid;
                    }
                    if (res.data.list[i].spikeT == 1) {
                      if (res.data.list[i].spike_end <= Date.parse(new Date()) / 1000) {
                        obj["url"] = '';
                        obj["backg"] = "#aaa";
                        obj["smtuan"] = '活动结束'
                      }
                    }
                  }
                }
                lists.push(obj);
                dataLists[indexid] = obj;
              }
              that.setData({
                lists: lists,
                cid: ""
              });

              wx.setStorage({
                key: "indexLists",
                data: dataLists
              })
            }

          })
        },
        fail: function () {
          wx.navigateTo({
            url: '../cell_selection/cell_selection',
          })
        }
      })
    }
  },
  showDetail: function (event) {
    var that = this;
    that.setData({
      hasblock: true,
      selectIndex: event.currentTarget.dataset.index
    })
    var index = event.currentTarget.dataset.index;
    if (that.data.lists[event.currentTarget.dataset.index].hasoption==0){
      if (that.data.allGoodsList[event.currentTarget.dataset.index].cnum <= 0) {
        wx.showToast({
          title: '库存已被别人抢光,请稍后刷新页面再试',
          icon: 'none'
        })
        that.setData({
          hasblock: false
        })
        return;
      }
    }
    //判断抢购时间
    if (that.data.allGoodsList[event.currentTarget.dataset.index].spike==1){
      console.log(Date.parse(new Date()) / 1000, that.data.lists[event.currentTarget.dataset.index].spike_on)
      if (that.data.lists[event.currentTarget.dataset.index].spike_on > Date.parse(new Date()) / 1000) {
        wx.showToast({
          title: '还未到抢购时间',
          icon: false
        })
        that.setData({
          hasblock: false
        })
        return
      }
      if (that.data.lists[event.currentTarget.dataset.index].spike_over < Date.parse(new Date()) / 1000){
        wx.showToast({
          title: '已过了抢购时间',
          icon: false
        })
        that.setData({
          hasblock: false
        })
        return
      }
    }
    setTimeout(function () {
      var _that = that;
      var { hasoption, good } = event.currentTarget.dataset;
      var id = event.currentTarget.dataset.id;
      if (good.smtuan == '售罄') return;
      _that.setData({
        num_count: 1
      })
      if (hasoption == '0') {
        wx.request({
          url: commonURLYY + 'op=cart_add',
          data: {
            areaid: _that.data.region.id,
            openid: app.data.openid,
            gid: id
          },
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            console.log(res)
            console.log(index)
            if ("lists[" + index + "].cnum") {
              var cnum1 = "lists[" + index + "].cnum"
            }
            that.setData({
              hasblock: false,
              [cnum1]: res.data.cnum
            })
            if (res.data.status == 0) {
              wx.showToast({
                title: res.data.result,
                icon: 'none'
              })
              return
            }
            // if(rea.data.data){
            if (res.data.data[res.data.data.length - 1].cnum < 0) {
              wx.showToast({
                title: '库存不足,请稍后刷新页面再试',
                icon: 'none'
              })
              return;
            }
            // }

            if (res.data.nkucun < 0) {
              wx.showToast({
                title: '库存不足,请稍后刷新页面再试',
                icon: 'none'
              })
              return;
            }
            if (res.data.status == 1) {
              wx.showToast({
                title: '添加成功',
                icon: 'success',
                duration: 1000
              })
            } else if (res.data.status == 0) {
              wx.showToast({
                title: '库存不足,请稍后刷新页面再试',
                icon: 'none',
                duration: 1000
              })
              _that.onShow();
            } else {
              that.setData({
                [cnum1]: 0
              })
              wx.showToast({
                title: res.data.result,
                duration: 1000
              })
            }
            var lists = res.data.data;
            var num = 0;
            for (var i = 0; i < lists.length; i++) {
              num = num + parseInt(lists[i].num);
            }
            wx.setTabBarBadge({
              index: 1,
              text: "" + num
            })
          }
        })
        // }

      } else {
        _that.data.showDetail = !_that.data.showDetail;
        let good = event.currentTarget.dataset.good;
        _that.setData({
          showDetail: _that.data.showDetail,
          selectProduct: good
        })
        _that.ajaxGuie(_that);
      }
    }, 600)
  },
  isClose: function () {
    this.setData({
      showDetail: false,
      hasblock: false,
    })
  },
  addSelect: function (event) {
    let good = event.currentTarget.dataset.good;
    this.data.count++;
    // if(good.gprice){
    //   this.data.totalPrice += Number(good.gprice);
    // }else{
    //   this.data.totalPrice += Number(good.gprice);
    // };
    // let num = this.data.totalPrice;
    // let totalPrice = Math.round(num*100)/100;
    // this.setData({
    //   count: this.data.count
    // })
  },
  showDialog: function () {     //购物车详情弹窗
    this.data.showDialog = !this.data.showDialog;
    var num_count = this.data.num_count;
    num_count = 1;
    this.setData({
      showDialog: this.data.showDialog,
      num_count: num_count
    })
  },
  chooseGG: function (event) {  //选择规格
    var that = this;
    console.log(event)
    var selectGindex = event.target.dataset.index;
    that.setData({
      selectGindex: selectGindex
    })
    var title = event.currentTarget.dataset.title;
    var options = this.data.guigeOptions;
    var currentItem = this.data.currentItem;
    var key = event.currentTarget.dataset.key;
    var guige = this.data.guige;
    currentItem[key].title = title;
    currentItem[key].item = event.currentTarget.dataset.index;
    for (var i = 0; i < options.length; i++) {
      for (var j = 0, ii = 0; j < currentItem.length; j++) {
        if (currentItem[j].title == '') {
          that.setData({
            'currentItem': currentItem,
            'guige': guige
          })
          return false;
        }
        var patt1 = new RegExp(currentItem[j].title);
        var result = patt1.test(options[i].title);
        result && ii++;
      }
      if (currentItem.length === ii) {
        that.data.istuan ? guige.price = options[i].marketprice : guige.price = options[i].productprice;
      }
    }
    this.setData({
      currentItem: currentItem,
      guige: guige
    })
  },
  ajaxGuie: function (that) {
    var ajaxguige = wx.getStorageSync('guige');
    if (ajaxguige.id === that.data.selectProduct.id) {//先判断该商品规格是否存在缓存中，否则ajax加载数据
      var data = ajaxguige.allspecs;
      var currentItem = [];
      for (var i = 0; i < data.length; i++) {
        currentItem.push({ title: "", item: "-1" });
      }
      if (data.length < 1) {
        return false
      }
      that.setData({
        guige: {
          price: "0.00",
          list: data
        },
        guigeOptions: ajaxguige.options,
        currentItem: currentItem
      })
    } else {
      wx.request({
        url: commonURL + 'op=goods_guige',
        data: {
          id: this.data.selectProduct.id,
          areaid: this.data.region.id,
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          var data = res.data.allspecs;
          var currentItem = [];
          if (data.length < 1) return;
          for (let i = 0; i < data.length; i++) {
            currentItem.push({ title: "", item: "-1" })
          }
          that.setData({
            guige: {
              price: '0.00',
              list: data
            },
            guigeOptions: res.data.options,
            currentItem: currentItem
          })
          var dataguige = res.data;
          dataguige.id = that.data.selectProduct.id;
          // wx.setStorage({               //把规格存储在缓存中
          //   key: 'guige',
          //   data: dataguige
          // })
        }
      })
    }
  },
  confirm: function (e) {
    console.log(e)
    var that = this;
    that.setData({
      hasblock: true
    })
    // selectIndex
    var index = that.data.selectIndex;
    var index1 = that.data.selectGindex;
    //判断抢购时间
    if (that.data.allGoodsList[index].spike == 1) {
      if (that.data.lists[index].spike_on > Date.parse(new Date()) / 1000) {
        wx.showToast({
          title: '还未到抢购时间',
          icon: false
        })
        that.setData({
          hasblock: false
        })
        return
      }
      if (that.data.lists[index].spike_over < Date.parse(new Date()) / 1000) {
        wx.showToast({
          title: '已过了抢购时间',
          icon: false
        })
        that.setData({
          hasblock: false
        })
        return
      }
    }
    if (that.data.lists[index].aCnum<=0){
      wx.showToast({
        title: '库存已被别人抢完,请稍后再试',
      })
      that.setData({
        hasblock: false
      })
      return;
    }
    // if (that.data.allGoodsList[index].)
    if (that.data.lists[index].options[index1].cnum <= 0) {
      wx.showToast({
        title: '库存已被别人抢完',
      })
      that.setData({
        hasblock: false
      })
      return;
    }
    for (var i = 0; i < that.data.currentItem.length; i++) {
      if (that.data.currentItem[i].item == "-1") {//判断是否选中规格
        wx.showToast({
          title: '请选择规格',
          icon: 'loading',
          duration: 1500
        })
        that.setData({
          hasblock: false
        })
        return false;
      }
    }
    var _guiges = [];
    var _currentItem = this.data.currentItem;
    var _id = e.currentTarget.dataset.id;
    _currentItem.forEach(function (item) {
      _guiges.push(item.title);
    })
    var _cid = this.data.guige.list[0].id
    this.data.totalPrice += Number(this.data.guige.price);
    this.data.showDetail = false;
    this.setData({
      showDetail: this.data.showDetail,
      totalPrice: this.data.totalPrice
    })
    wx.request({
      url: commonURLYY + 'op=cart_add',
      data: {
        openid: app.data.openid,
        gid: this.data.selectProduct.id,
        guige: _guiges.join('+'),
        areaid: this.data.region.id,
        num: this.data.num_count
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        // that.data.lists[that.data.selectIndex].options[that.data.selectGindex].cnum
        var cnum1 = "lists[" + index + "].options[" + index1 + "].cnum"
        that.setData({
          [cnum1]: res.data.cnum,
          hasblock: false
        })
        if (res.data.data[res.data.data.length - 1].cnum < 0) {
          wx.showToast({
            title: '库存已被抢完',
          })
          return;
        } else {
          if (res.data.status == -1) {
            wx.showToast({
              title: res.data.result,
              icon: 'loading',
              duration: 1000
            })
            return false;
          }
          if (_id == '2') {
            wx.navigateTo({
              url: '../index_cart/index_cart'
            })
          } else {
            var lists = res.data.data;
            var num = 0;
            var Allcnum=0;
            for (var i = 0; i < lists.length; i++) {
              num = num + parseInt(lists[i].num);
            }
            wx.setTabBarBadge({
              index: 1,
              text: "" + num
            })
            wx.showToast({
              title: '添加成功',
              icon: 'success',
              duration: 1000
            })
            for (var i = 0; i < that.data.lists[index].options.length;i++){
              console.log(Allcnum)
              Allcnum += parseInt(that.data.lists[index].options[i].cnum)
            }
            console.log(Allcnum)
            var cnum1 = "lists[" + index + "].cnum"
            var aCnum = "lists[" + index + "].aCnum"
            console.log(Allcnum)
            that.setData({
              [cnum1]: Allcnum,
              hasblock: false,
              [aCnum]: Allcnum
            })
          }
        }
      }
    })
  },
  // 导航详情
  goNavBarDetail: function (e) {
    var index = e.currentTarget.dataset.index;
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/navbar-detail/navbar-detail?index=' + index + '&id=' + id
    })
  },
  reduceCount: function () {
    var num_count = this.data.num_count;
    if (num_count <= 1) {
      num_count = 1;
    } else {
      num_count--;
    }
    this.setData({
      num_count: num_count
    })
  },
  addCount: function (e) {
    var num_count = this.data.num_count;
    num_count++;
    this.setData({
      num_count: num_count
    })
  },
  select_tuan: function (selltype) {
    var selltype_text = '';
    switch (selltype) {
      case '1':
        selltype_text = '去开团  >';
        break;
      case '2':
        selltype_text = '去开团  >';
        break;
      case '3':
        selltype_text = '去开团  >';
        break;
      case '4':
        selltype_text = '去开团  >';
        break;
      case '5':
        selltype_text = '去开团  >';
        break;
      case '6':
        selltype_text = '去开团  >';
        break;
      case '7':
        selltype_text = '去开团  >';
    }
    return selltype_text = '去开团';
  }
  // send_num: function (num) {
  //   wx.request({
  //     url: commonURLYY+ 'op=cart_add',
  //     data: {
  //       num: num
  //     },
  //     header:{
  //       'content-type': 'application/json'
  //     },
  //     success:function (res) {

  //     }
  //   })
  // }

})
